const { $Toast } = require('../../../utils/iview/base/index');
const Tools = require('../../../utils/modules/Tools');
import NetWork from '../../../utils/modules/NetWork';

const app = getApp();

var QQMapWX = require('../../../utils/qqmap-wx-jssdk.min.js');
var qqmapsdk;
Page({
  data: {
    order_status:'',
    type: 3,
    banner: null,
    student: null,
    shopList: null,
    //门店展示的数据
    shopname: [],
    order_id: 0,
  
    auth: false,
    isloade: {
      hidden: false
    },
    _baseUrl: app.globalData._baseUrl
  },
  onLoad(options) {
    var _that = this
    var { type } = options;
    if (type == 9) {
      _that.setTitle('已取消');
    } else if (type == 3) {
      _that.setTitle('服务中');
    } else if (type == 1) {
      _that.setTitle('已完成');
    }
    _that.setTitle('订单详情');
    _that.setData({
      order_status: type
    });
    
  },
  onShow: function () {
    let _that = this;
    var vehicle = wx.getStorageSync('vehicle');
    _that.setData({
      indexs: vehicle
    })
    _that.order();
  },

  bindDateils(e) {
    wx.navigateTo({
      url: 'orderDetails?id='+ e.currentTarget.dataset.id,
    })
  },



  //取消服务 & 服务中 & 已完成
  order() {
    let _that = this;
    var token = wx.getStorageSync('token');
    if (!token) {
      return;
    }

    let net = new NetWork(_that.data._baseUrl)
    net._request({
      url: 'api/v1/order/myOrder',
      data: {
        token: token,
        order_status: _that.data.order_status
      },
      method: 'POST'
    }, '', res => {

      _that.setData({
        order: res.data.data
      })

    }, res => {
      if (res.data.error_code == 400 && res.data.msg == 'token无效或已过期') {
        app.refreshtoken(token);
        setTimeout(() => {
          _that.order();
        }, 1500)
      }
    });
  },





  /* 拨打电话 */
  telPhone() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: ''
    }, res => {

    });
  },
 


  onReady: function (e) {

  },




  /* 修改头部标题 */
  setTitle(str) {
    wx.setNavigationBarTitle({
      title: str,
      success: function () {

      }
    })
  },
  onShareAppMessage(str) {
    return {
      title: str,
      path: this.route
    }
  },


  /* 隐藏分享功能 */
  hideShare() {
    wx.hideShareMenu()
  },
  /* 分享功能 */
  showShare() {
    wx.showShareMenu()
  },
  /* 下拉刷新触发功能 */
  onPullDownRefresh() {
    // 下拉刷新事件
    // wx.startPullDownRefresh
    // wx.stopPullDownRefresh
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000)

  },

  /* 开启上拉到底部触发功能 */
  startDonwEven() {
    wx.startPullDownRefresh()
  },
  /* 停止上拉到底部触发功能 */
  stopDownEven() {
    wx.stopPullDownRefresh()
  },
  onReachBottom() {
    // 上拉触底事件
    //console.log('触发触底事件')
  },

  onPageScroll(res) {
    // 页面滚动事件
    //console.log(res.scrollTop)
  },

  userInfo(e) {
    let _userInfo = e.detail.userInfo;
    let net = new NetWork(app.globalData._baseUrl);

    if (_userInfo) {
      this.setData({
        auth: true
      })
    }

    wx.login({
      success(res) {
        //console.log('小程序登录信息', res)
        if (res.code) {
          net._request({
            url: 'login',
            data: {
              code: res.code
            },
          }, false, sres => {

          });
        }
      }
    })
  }


})